package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.BrandMapper;
import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.pojo.product.Brand;
import com.atguigu.spzx.model.vo.common.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

@Service
@Transactional
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {
    @Autowired
    private BrandMapper brandMapper;

    @Override
    public Page<Brand> findPage(Integer pageNum, Integer pageSize, @RequestBody String brandName) {
        Page<Brand> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Brand> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(brandName)){
            wrapper.like("name",brandName);
        }
        return brandMapper.selectPage(page, wrapper);
    }
}
